package com.sto.stoapp.activity.administrator.hardware;

import android.location.Location;
import android.os.Bundle;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.manager.GpsManager;
import com.sto.stoapp.manager.GpsManager.OnGpsChangedListener;
import com.sto.stoapp.util.Helper;
import com.sto.stoapp.widget.StoHomeActivity;

/**
 * GPS搜星
 * 
 * @author mgf
 * 
 */
public class AdminGpsTestActivity extends StoHomeActivity {

	private GpsManager gpsManager;

	private TextView gpsResult;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.admin_gps_test);
		this.setTitleBottom(R.string.gps_source,
				HomeBroadAction.ADMINISTRATOR_BROAD);
		gpsManager =  GpsManager.getInstance(this);
		gpsResult = (TextView) findViewById(R.id.gps_result);
		gpsManager.setOnGpsChangedListener(new OnGpsChangedListener() {

			@Override
			public void onGpsChangedListener(Location location) {
				if (location == null) {
					Helper.showToast(AdminGpsTestActivity.this, "没有搜到星");
					return;
				}
				StringBuffer sb = new StringBuffer();
				sb.append(getString(R.string.longitude))
						.append(location.getLongitude()).append("\r\n")
						.append(getString(R.string.latitude))
						.append(location.getLatitude()).append("\r\n")
						.append(getString(R.string.speed))
						.append(location.getSpeed()).append("\r\n")
						.append(getString(R.string.elevation))
						.append(location.getAltitude()).append("\r\n")
						.append(getString(R.string.location))
						.append(location.getBearing());
				gpsResult.setText(sb.toString());
			}
		});

	}

}
